#define _CRT_SECURE_NO_WARNINGS 1

#include<iostream>
#include<algorithm>
#include<vector>

using namespace std;

struct compare
{
    bool operator()(vector<int>& a, vector<int>& b)
    {
        if (a[0] == b[0])    return a[1] < b[1];
        return a[0] < b[0];
    }
};
vector<vector<int>> merge(vector<vector<int>>& intervals) {
    sort(intervals.begin(), intervals.end(), compare());
    vector<vector<int>> res;
    for (int i = 0; i < intervals.size(); i++)
    {
        vector<int>& v = intervals[i];
        int j;
        for (j = i + 1; j < intervals.size(); j++)
        {
            if (v[1] >= intervals[j][0])
                v[1] = max(v[1], intervals[j][1]);
            else break;
        }
        i = j - 1;
        res.push_back(v);
    }
    return res;
}